﻿namespace Auros.Categorisation.Samples.UserControls
{
    using System;
    using umbraco.NodeFactory;
    using umbraco.presentation;

    public partial class ListPageCategories : System.Web.UI.UserControl
    {
        private Node currentNode = null;

        /// <summary>
        /// Gets the current node.
        /// </summary>
        /// <value>The current node.</value>
        private Node CurrentNode
        {
            get
            {
                if (currentNode == null && UmbracoContext.Current.PageId.HasValue)
                    currentNode = new Node(UmbracoContext.Current.PageId.Value);

                return currentNode;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.CurrentNode != null)
            {
                this.CategoryList.DataSource = this.CurrentNode.GetCategories("categories");
                this.CategoryList.DataBind();
            }
        }
    }
}